const express = require("express");
const qs = require("querystring");
const url = require("url");
const path = require("path");
const router = express.Router();
const db = require("../../config/dbserver.js");

router.get("/go", (req, res) => {
  // 发送指定路径的 HTML 文件
  // const goPagePath = path.join(__dirname, "public", "go.html");
  const goPagePath = path.resolve(__dirname, "../../public/", "go1.html");
  res.sendFile(goPagePath, (err) => {
    if (err) {
      res.status(404).send("页面不存在");
    }
  });
});

router.get("/go/com.tauritech.weather.basic", (req, res) => {
  // 发送指定路径的 HTML 文件
  // const goPagePath = path.join(__dirname, "public", "go.html");
  const goPagePath = path.resolve(__dirname, "../../public/", "go.html");
  res.sendFile(goPagePath, (err) => {
    if (err) {
      res.status(404).send("页面不存在");
    }
  });
});

// admin 重定向到 public/admin/index.html
router.get("/admin/*", (req, res) => {
  const adminPagePath = path.resolve(
    __dirname,
    "../../public/admin/index.html"
  );
  res.sendFile(adminPagePath, (err) => {
    if (err) {
      res.status(404).send("页面不存在");
    }
  });
});

module.exports = router;
